﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using BE.Web.Betfair.Interface;
using BE.Common.User;
using BE.Web.Betfair.EBC;
using BE.Security;
using BE.Web.Betfair.Interface.Entities;
using System.Collections.ObjectModel;
using BE.Web.Betfair.Interface.Requests;


namespace BE.Web.Betfair
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Start");

            #region readdata
            
            string user, pw;

            Console.Write("User:");
            user = Console.ReadLine();

            Console.Write("PW:");
            pw = Console.ReadLine();

            #endregion

            BetfairProduct product = BetfairProduct.Free;

            Credentials credits = new Credentials(user,pw.ToSecureString());
            BetfairEBC adapter = new BetfairEBC();
             
            Session session =  adapter.Login(credits, product);

            ReadOnlyCollection<BetEventType> result =  adapter.GetAllEventTypes(session);
            result = adapter.GetAllEventTypes(session);

            if (result != null)
            {
                BetEventType curEvent = result.Where<BetEventType>(p => { return p.Id == 1; }).First<BetEventType>();

                ReadOnlyCollection<BetEvent> events = null;

                BetEventByTypeRequest request = new BetEventByTypeRequest(curEvent, session, p => events = p);
                adapter.GetEventsOfType(request);


                if (events != null)
                {
                    BetEvent buli = events.Where<BetEvent>(p => {return p.Id == 257608; }).First<BetEvent>();

                    if(buli != null)
                    {
                        BetEventByParentEventRequest childRequest = new BetEventByParentEventRequest(buli,session,
                            p=>{
                            if(p != null)
                            {
                                foreach (BetEvent myEvent in p)
                                {
                                    Console.WriteLine(myEvent.Name);
                                }
                                
                            }});


                        adapter.AddMarketsAndSubEvents(childRequest);
                    }
                }

                int j=1;

                ReadOnlyCollection<BetMarket> markets = null;
                adapter.GetMarketsOfEvent(new EventMarketsRequest(session, events[j], p => markets = p));

                if (markets != null)
                {
                }
            }

            adapter.Logout(session);
            Console.WriteLine("Wait");
            Console.ReadKey();
        }
    }
}
